package com.todod.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.todod.entity.QueryEntry;
import com.todod.entity.ResultData;
import com.todod.model.BaseNotice;
import com.todod.service.BaseNoticeSercice;

@RestController
@RequestMapping("/baseNotice")
public class BaseNoticeControllor {

	@Autowired
	private BaseNoticeSercice baseNoticeSercice;

	/**
	 * @Title: getList
	 * @Description:获取公告列表
	 * @author dyl
	 * @date 2022-07-22
	 * @param queryNotice
	 * @return
	 */
	@PostMapping("/getList")
	public ResultData getList(@RequestAttribute Long _userId, @RequestBody QueryEntry queryNotice) {

		IPage<BaseNotice> wappers = baseNoticeSercice.getList(queryNotice);
		return ResultData.success("OK", wappers);
	}

	/**
	 * @Title: save
	 * @Description: 新增公告
	 * @author dyl
	 * @date 2022-07-22
	 * @param _userId
	 * @param baseNotice
	 * @return
	 */
	@PostMapping("/save")
	public ResultData saveNotice(@RequestAttribute Long _userId, @RequestBody BaseNotice baseNotice) {

		baseNoticeSercice.saveData(_userId, baseNotice);
		return ResultData.success();
	}

	/**
	 * @Title: edit
	 * @Description: 编辑公告
	 * @author dyl
	 * @date 2022-07-22
	 * @param _userId
	 * @param baseNotice
	 * @return
	 */
	@PostMapping("/edit")
	public ResultData edit(@RequestAttribute Long _userId, @RequestBody BaseNotice baseNotice) {
		baseNoticeSercice.editData(_userId, baseNotice);
		return ResultData.success();
	}

	/**
	 * @Title: info
	 * @Description: 获取公告信息
	 * @author dyl
	 * @date 2022-07-22
	 * @param code
	 * @return
	 */
	@GetMapping("/getInfo")
	public ResultData getInfo(Long code) {
		if (code == null) {
			return ResultData.error(ResultData.PARAM_ERROR_CODE, "参数错误");
		}
		Map<String, Object> info = baseNoticeSercice.getInfo(code);
		return ResultData.success("ok", info);
	}

	/**
	 * @Title: delete
	 * @Description: 删除公告信息
	 * @author dyl
	 * @date 2022-07-22
	 * @param ids
	 * @return
	 */
	@PostMapping("/delete")
	public ResultData delete(String ids) {
		baseNoticeSercice.deleteData(ids);
		return ResultData.success();
	}

}
